import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-04-02
 * Time: 10:42
 */
public class Demo1 {
    public static CountDownLatch countDownLatch;
    public static void func(int count) throws InterruptedException {
        countDownLatch = new CountDownLatch(count);
        for (int i = 0; i < count; i++) {
            int n = i;
            Thread thread = new Thread(()->{
                System.out.println(n);
                countDownLatch.countDown();
            });
            Thread.sleep(100);
            thread.start();
        }

    }
    public static void main(String[] args) throws InterruptedException {
        int count = 20;
        func(count);
        countDownLatch.await();
        System.out.println("OK");
    }
}